/**
 * 
 */
package view;

import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JLayeredPane;
import javax.swing.JPanel;

import model.GameDriver;

import common.DataManager;

import controller.Controller;
public class InventoryPanel extends JLayeredPane implements MouseListener {
	
	private static final int INVENTORY_WIDTH = 250;
	private static final int INVENTORY_HEIGHT = 500;
	private static final int TILE_WIDTH = 50;
	private static final int TILE_HEIGHT = 50;
	
	private JPanel backgroundPanel;
	private JPanel cardPanel;
	private CargoPanel cargoPanel;
	private StorePanel storePanel;
	private boolean storePanelIsFront = true;
	
	public InventoryPanel(){
		super();
		
		this.setLayout(null);
		this.setBackground(Color.black);
		addMouseListener(this);

		backgroundPanel = new JPanel(new GridLayout(1,1));
		ImagePanel backgroundImage = new ImagePanel(DataManager.INVENTORY_BACKGROUND);
		backgroundPanel.add(backgroundImage);
		backgroundPanel.setOpaque(false);
		backgroundPanel.setSize(backgroundImage.getPreferredSize());
		
		cardPanel = new JPanel(new CardLayout());
		cardPanel.setOpaque(false);
		cargoPanel = new CargoPanel();
		storePanel = new StorePanel();
		
		cardPanel.add(storePanel, "STORE_PANEL");
		cardPanel.add(cargoPanel, "CARGO_PANEL");
		cardPanel.setSize(new Dimension(INVENTORY_WIDTH,INVENTORY_HEIGHT));
		this.add(cardPanel);
		this.add(backgroundPanel);
		this.setPreferredSize(backgroundPanel.getPreferredSize());
		
		cardPanel.setLocation(0, 0);
		
		CardLayout cl = (CardLayout)(cardPanel.getLayout());
		cl.show(cardPanel, "CARGO_PANEL");
	}
	
	/**
	 * Tells the store panel to update itself
	 * 
	 * @param gameDriver
	 */
	public void updateStore(GameDriver gameDriver){
		this.storePanel.updateStore(gameDriver);
	}
	
	/**
	 * Tells the cargo panel to update itself
	 * 
	 * @param gameDriver
	 */
	public void updateCargo(GameDriver gameDriver){
		this.cargoPanel.updateCargo(gameDriver);
	}
	
	/**
	 * displays the store panel
	 */
	public void setStorePanelFront(){	
		CardLayout cl = (CardLayout)(cardPanel.getLayout());
		cl.show(cardPanel, "STORE_PANEL");
		storePanelIsFront = true;
	}
	
	/**
	 * displays the cargo panel
	 */
	public void setCargoPanelFront(){
		CardLayout cl = (CardLayout)(cardPanel.getLayout());
		cl.show(cardPanel, "CARGO_PANEL");
		storePanelIsFront = false;
	}
	
	/**
	 * Resets all the items in the cargo and store panels to not be highlighted
	 */
	public void unhighlightAllItems(){
		storePanel.unhighlightAllItems();
		cargoPanel.unhighlightAllItems();
	}

	/* (non-Javadoc)
	 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
	 */
	@Override
	public void mouseClicked(MouseEvent arg0) {
		//this.switchPanel();
		Controller.inventoryBackgroundClicked();
	}

	/* (non-Javadoc)
	 * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
	 */
	@Override
	public void mouseEntered(MouseEvent arg0) {

	}

	/* (non-Javadoc)
	 * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
	 */
	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
	 */
	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	/* (non-Javadoc)
	 * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
	 */
	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

}
